/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template sigFile, choose Tools | Templates
 * and open the template in the editor.
 */
package cn.ac.iie.di.server;

import cn.ac.iie.di.global.GlobalParas;
import static cn.ac.iie.di.global.GlobalParas.TYPE_PYQ;
import cn.ac.iie.di.msg.JsonMsgSender;
import cn.ac.iie.di.friend.JsonFriendSender;
import cn.ac.iie.di.friend.RetryTask;
import cn.ac.iie.di.splitor.UngzipSplitor;
import cn.ac.iie.di.ungzip.UngzipHandler;
import org.apache.log4j.Logger;
import org.apache.log4j.PropertyConfigurator;

/**
 *
 * @author lenovo-pc
 */
public class FriendParserStartup {

    static Logger logger = null;

    static {
        PropertyConfigurator.configure(ClassLoader.getSystemClassLoader().getResource("log4j.properties"));
        logger = Logger.getLogger(FriendParserStartup.class.getName());
    }

    public static void main(String[] args) {
        startunGzFile();
        startGzSplitor();
        startBcpsSender();
        startSend();
    }

    public static void startSend() {
        Thread pyqThread = new Thread(new JsonMsgSender(GlobalParas.POOL_MSG, GlobalParas.IP_PORT, GlobalParas.MQ_PYQ, GlobalParas.TYPE_PYQ, GlobalParas.sendPYQQueue, "JsonPYQTask", "PYQ"));
        pyqThread.setName("JsonPYQSender");
        pyqThread.start();
        Thread cmdThread = new Thread(new JsonMsgSender(GlobalParas.POOL_MSG, GlobalParas.IP_PORT, GlobalParas.MQ_CMD, GlobalParas.TYPE_CMD, GlobalParas.sendCMDQueue, "JsonCMDTask", "CMD"));
        cmdThread.setName("JsonCMDSender");
        cmdThread.start();
        Thread userThread = new Thread(new JsonMsgSender(GlobalParas.POOL_MSG, GlobalParas.IP_PORT, GlobalParas.MQ_USER, GlobalParas.TYPE_USER, GlobalParas.sendUSERQueue, "JsonUSERTask", "USER"));
        userThread.setName("JsonUSERSender");
        userThread.start();
        Thread mediaThread = new Thread(new JsonMsgSender(GlobalParas.POOL_MSG, GlobalParas.IP_PORT, GlobalParas.MQ_MEDIA, GlobalParas.TYPE_MEDIA, GlobalParas.sendMediaQueue, "JsonMEDIATask", "MEDIA"));
        mediaThread.setName("JsonMEDIASender");
        mediaThread.start();
    }

    public static void startBcpsSender() {
        for (int i = 0; i < 4; i++) {
            Thread thread = new Thread(new JsonFriendSender());
            thread.setName("JsonFriendSender" + "_" + i);
            thread.start();
        }
    }

    public static void startunGzFile() {
        for (int i = 0; i < 4; i++) {
            Thread thread = new Thread(new UngzipHandler());
            thread.setName("unGzBcps" + "_" + i);
            thread.start();
        }
    }

    public static void startGzSplitor() {
        Thread thread = new Thread(new UngzipSplitor(GlobalParas.ZIP_DIR));
        thread.setName("JsonGz" + "_bcps");
        thread.start();
    }

}
